<?php

class SON_Forms_UsuarioCadastro extends Zend_Form
{
    public function init()
    {
        $this->setMethod('post');

        $nome = new Zend_Form_Element_Text('nome');
        $nome->setRequired(true)
        	 ->addFilter('StripTags')
        	 ->addFilter('StringTrim')
        	 ->addValidator('NotEmpty', true, array('messages' => 'Informe um nome'))
        	 ->setAttrib('autofocus', 'autofocus')
        	 ->setAttrib('class', 'form-control')
        	 ->setAttrib('placeholder', 'Nome')
        	->setAttrib('required', 'required');
        $this->addElement($nome);

        $email = new Zend_Form_Element_Text('email');
        $email->setRequired(true)
        	  ->addFilter('StripTags')
        	  ->addFilter('StringTrim')
        	  ->addValidator('NotEmpty', true, array('messages' => 'Informe um e-mail'))
        	  ->addValidator('EmailAddress', true, array('messages' => 'E-mail inválido'))
        	  ->addValidator('Db_NoRecordExists', false, array('table' => 'usuario', 'field' => 'email', 'messages' => 'E-mail já cadastrado'))
        	  ->setAttrib('class', 'form-control')
        	  ->setAttrib('placeholder', 'E-mail')
        	->setAttrib('required', 'required');
        $this->addElement($email);
        
        $senha = new Zend_Form_Element_Password('senha');
        $senha->setRequired(true)
		      ->addFilter('StripTags')
		      ->addFilter('StringTrim')
		      ->addValidator('NotEmpty', false, array('messages' => 'Informe uma senha'))
		      ->setAttrib('class', 'form-control')
		      ->setAttrib('placeholder', 'Senha')
        	->setAttrib('required', 'required');
        $this->addElement($senha);

        $fc = Zend_Controller_Front::getInstance();
        $captcha = new Zend_Form_Element_Captcha(
        	'captcha',
        	array(
        		//'label' => 'Caracteres',
				'captcha' => array(
					'captcha' => 'Image',
					'wordLen' => 6,
					'timeout' => 300,
					'width' => 360,
					'font' => 'assets/img/captcha/font/verdana.ttf',
					'imgDir' => 'assets/img/captcha/',
					'imgUrl' => $fc->getBaseUrl() . '/assets/img/captcha/',
					'messages' => array('badCaptcha' => 'Captcha incorreto')
				)
			)
		);
        $captcha->setAttrib('class', 'form-control')
        	->setAttrib('required', 'required');
        $this->addElement($captcha);
        
        $nome->removeDecorator('HtmlTag')->removeDecorator('Label')->removeDecorator('Errors');
        $email->removeDecorator('HtmlTag')->removeDecorator('Label')->removeDecorator('Errors');
        $senha->removeDecorator('HtmlTag')->removeDecorator('Label')->removeDecorator('Errors');
        $captcha->removeDecorator('HtmlTag')->removeDecorator('Label')->removeDecorator('Errors');
    }

}